﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AD.Model;
using AD.DAL;

public partial class Manager_User_PageData_ManagerUserList : WebManagerForm
{
    public IList<ManagerUserMod> Users = new List<ManagerUserMod>();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            SetDataBind();
        string action = Request.QueryString["action"];
        string idstr = Request.QueryString["ids"];
        string paramss = Request.QueryString["params"];
        if (!string.IsNullOrEmpty(action))
        {
            int id = 0;
            int.TryParse(idstr, out id);
            if (action.Equals("delete")) {
                AD.DAL.ManagerUserDAL.Delete(id);
                SetDataBind();
            }
            else if (action.Equals("edit")) { 
            
            }
            else if (action.Equals("valid"))
            {
                ManagerUserMod user = ManagerUserDAL.GetUserByIdToMod(id);
                if (user != null)
                {
                    user.IsValid = !user.IsValid;
                    ManagerUserDAL.Update(user);
                    SetDataBind();
                }
            }
            else if (action.Equals("gopage")) {
                SetDataBind();
            }
        }
    }

    void SetDataBind() {
        Users = ManagerUserDAL.GetUsersToList();
        if (Users == null) { Users = new List<ManagerUserMod>(); }
    }
}